<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<% String context = request.getContextPath(); %>
<html>
<head>
  <title>已办列表</title>
  <link rel="stylesheet" href="<%=context %>/Source/lib/layui/css/layui.css">
  <style>
    .layui-table, .layui-table-view{
      margin: 0;
    }
  </style>
  <link rel="stylesheet" type="text/css" href="<%=context %>/Source/lib/ligerUI/skins/ligerui-icons.css" />
  <link rel="stylesheet" type="text/css" href="<%=context %>/Source/lib/ligerUI/skins/Aqua/css/ligerui-all.css" />

</head>

<body style="padding: 0;overflow:hidden;">
<%-- 工具栏 --%>
<div id="toolbar"></div>
<!-- 2018/5/13新增，对外提供服务时，由外部服务决定获取谁的流程和什么应用下的流程 -->
<input type="hidden" id="app" value="${appName}" />
<input type="hidden" id="userId" value="${userId}" />


<%-- 表格 --%>
<div id="grid">
  <div id="mainGrid" style="margin: -1px; min-width: 680px;"></div>
</div>
</body>
<script src="<%=context %>/gooflow/jquery.min.js"></script>
<script src="<%=context %>/Source/lib/layui/layui.js"></script>
<script src="<%=context %>/microcore/commonjs/utility.js"></script>
<script src="<%=context %>/Source/lib/ligerUI/js/ligerui.all.js"></script>
<script type="text/javascript">
    var path = '<%=context %>';
    var _path = path+"/flow/task";
    var _process = path+"/flow/process";

    <!-- 2018/5/13新增，对外提供服务时，由外部服务决定获取谁的流程和什么应用下的流程 -->
    var apps = $('#app').val();
    apps = apps==''?'':'&appName='+apps
    var userId = $('#userId').val();
    userId = userId==''?'':'&userId='+userId

    // 表格
    var table;
    layui.use(['table'], function(){

        table = layui.table;

        table.render({
            elem: '#mainGrid'
            , url: _path + "/getDeal?rnd=" + Math.random() + apps +userId //数据接口
            ,method:'post'
            // , page: true //开启分页
            , cols: [[ //表头
                {field: 'startUser', title: '流程发起人', align: 'center', sort: true}
                , {field: 'processName', title: '业务名称', align: 'center', sort: true}
                , {field: 'flowRemark', title: '工作说明', align: 'center', sort: true}
                , {field: 'taskName', title: '节点名称', align: 'center', sort: true}
                , {field: 'completeRemark', title: '处理摘要', align: 'center', sort: true}
                , {field: 'lastCompleteTime', title: '处理时间', align: 'center', sort: true}
                , {title: '操作', align: 'center', templet: function (item) {
                        var result ="";
                        if( item.viewPageUrl !=null){
                            result = "<a class=\"layui-btn layui-btn-sm\" href=\"javascript:void(0)\" onclick=\"f_view('" + item.viewPageUrl + "')\">显示单据</a>";
                        }
                        result += " <a class=\"layui-btn layui-btn-sm\" href=\"javascript:void(0)\" onclick=\"f_status('" + item.instanceId + "')\">流程状态</a>";
                        result += " <a class=\"layui-btn layui-btn-sm\" href=\"javascript:void(0)\" onclick=\"f_picture('" + item.instanceId + "')\">流程图</a>";
                        if(item.allowRecall=="0"){	//设置为0就会根据数据库中存储的字段判断
                            if(item.isCancel == "1")
                                result += " <a class=\"layui-btn layui-btn-sm\" href=\"javascript:void(0)\">已撤销</a>";
                            else
                                result += " <a class=\"layui-btn layui-btn-sm\" href=\"javascript:void(0)\" onclick=\"f_cancel('" + item.instanceId + "','" + item.taskLogicalName + "')\">撤销</a>";
                        }
                        result += "<input id=\"nodeId\" type=\"hidden\" name=\"country\" value=\""+item.nodeId+"\" />"
                        result += "<input id=\"taskLogicalName\" type=\"hidden\" name=\"country\" value=\""+item.taskLogicalName+"\" />"
                        return result;
                    }
                }
            ]]
            ,response: {
                statusCode: 200 //成功的状态码，默认：0
            }
        });
    });

    $(function () {
        $("#grid").height(document.documentElement.clientHeight - $(".toolbar").height());
    });

    // 表格刷新
    function f_load() {
        layui.table.reload('mainGrid', {
            url:_path + "/getDeal?rnd=" + Math.random() + apps +userId
        });
    }

    function f_view(viewPageUrl) {
        window.open(viewPageUrl);
    }

    // 流程状态
    function f_status(instanceId) {
        var url;
        url = _path + "/toTaskDealHistoryList?instanceId="+instanceId;
        layer.open({
            type: 2,
            title: '处理历史',
            shadeClose: true,
            shade: 0.8,
            area: ['80%', '500px'],
            content:url, //iframe的url
        });
    }

    function f_picture(instanceId) {
        window.open(_process + "/processViewBpmn?instanceId=" + instanceId+"&nodeId=" + $("#nodeId").val().trim());
    }

    // 撤销
    function f_cancel(instanceId,taskName) {
        app.ajax({
            url:_path + "/cancelTask",
            data: {
                indtsnceId: instanceId,
                taskName: taskName
            },
            success: function (result) {
                if (result.isError == false) {
                    layer.msg("撤销成功!");
                    f_load();
                } else {
                    layer.msg(result.message);
                }
            }
        });
    }
</script>
</html>
